<?php use_stylesheet('/sfDoctrinePlugin/css/default.css'); ?>
<?php use_stylesheet('/sfDoctrinePlugin/css/global.css'); ?>
<div id="sf_admin_container">
    <div id="i18n_wrapper">
        <h1>I18n messages List</h1>
        <div class="search">
            <form action="<?php echo url_for(array('module'=>'i18n', 'action'=>'index')); ?>" method="get">
                <label>Search source:</label>
                <input type="text" name="search" value="<?php if(isset($search)) echo $search; ?>">
                <input type="button" value="GO"/>
            </form>
        </div>
        
        <div class="separator"><!----></div>

        <table class="sf_admin_list">
            <thead>
                <tr>
                    <th>Source</th>
                    <?php foreach($languages as $language): ?>
                    <th>Target <?php echo $language->getCode(); ?></th>
                    <?php endforeach; ?>

                </tr>
            </thead>
            <tbody>
                <?php foreach ($i18n_messages as $i18n_message): ?>
                    <tr>
                        <td><?php echo $i18n_message->source ?></td>
                        <?php foreach($languages as $language): ?>
                        <?php
                            $id = 'id_'.$language->getId();
                            $target = 'target_'.$language->getId();
                        ?>
                        <td>
                            <?php if(!empty($i18n_message->$id)): ?>
                            
                            <a href="<?php echo url_for(array('module'=>'i18n', 'action'=>'edit', 'id'=>$i18n_message->$id)) ?>" class="edit">
                                <?php echo $i18n_message->$target ?>
                            </a>
                            <?php echo link_to('<!---->', 'i18n/delete?id='.$i18n_message->$id, array('method' => 'delete', 'confirm' => 'Are you sure?', 'class' => 'delete')) ?>
                            <?php else: ?>
                            <a href="<?php echo url_for(array('module'=>'i18n', 'action'=>'new', 'trans_unit_id'=>$i18n_message->trans_unit_id, 'source'=>$i18n_message->source, 'i18n_language_id'=>$language->getId())) ?>" class="add">
                                add
                            </a>
                            <?php endif;?>
                        </td>
                        <?php endforeach; ?>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
            <tfoot>
                <tr>
                    <td colspan="3">
                        <div class="pagination">
                            <?php $url_array = array('module'=>'i18n', 'action'=>'index'); ?>
                            <?php if(!empty($search)) $url_array['search'] = $search; ?>
                            <a href="<?php echo url_for($url_array+array('page'=>1)) ?>">
                                <<
                            </a>

                            <a href="<?php echo url_for($url_array+array('page'=>$pager->getPreviousPage())) ?>">
                                <
                            </a>

                        <?php foreach ($pager->getLinks() as $page): ?>
                        <?php if ($page == $pager->getPage()): ?>
                        <?php echo $page ?>
                        <?php else: ?>
                                    <a href="<?php echo url_for($url_array+array('page'=>$page)) ?>"><?php echo $page ?></a>
                        <?php endif; ?>
                        <?php endforeach; ?>

                                    <a href="<?php echo url_for($url_array+array('page'=>$pager->getNextPage())) ?>">
                                        >
                                    </a>

                                    <a href="<?php echo url_for($url_array+array('page'=>$pager->getLastPage())) ?>">
                                        >>
                                    </a>
                                </div>
                                <div class="global-actions">
                                    <a href="<?php echo url_for('i18n/clearCache') ?>">clear cache</a>
                                    <a href="<?php echo url_for('i18n/importFromFile') ?>" onClick="return confirm('Это полностью перепишет базу из файла. Вы уверены?');" class="red">
                                        import from file source
                                    </a>
                                    <a href="<?php echo url_for('i18n/exportToFile') ?>" onClick="return confirm('Это запишет данные из базы данных в xml-файлы. Вы уверены?');" class="red">
                                        export to file
                                    </a>
                                    <a href="<?php echo url_for('i18n/new') ?>">New</a>
                                </div>
                            </td>
                        </tr>
                    </tfoot>
    </div>
</div>